program r2hc
	implicit none
	include 'fftw3.f'
	integer, parameter:: N=16
	double precision:: in(N), out(N), inverseout(N)
	integer:: p
	integer:: i, j, k
	double precision:: PI
	PI = 4.0* datan(1.0d0)
	do i = 1, N
		in(i) = dsin( 2.0 * PI * dble(i-1) / dble(N) + PI / N )
	end do		
	call dfftw_plan_r2r_1d( p, N, in, out, FFTW_R2HC, FFTW_ESTIMATE)
	call dfftw_execute(p)
	call dfftw_destroy_plan(p)
	do k = 1, N
		print *, out(k)
	end do
	call dfftw_plan_r2r_1d( p, N, out, inverseout, FFTW_HC2R, &
		FFTW_ESTIMATE )
	call dfftw_execute(p)
	call dfftw_destroy_plan(p)

	print *, "ERROR="
	do i = 1, N
		print *, dabs( in(i) - inverseout(i) / N )
	end do

	stop
end program	
